package com.jishuo.base.interceptor;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;
import java.util.List;

/**
 * 拦截器配置，加载过滤Url
 */
@Data
@Configuration
@ConfigurationProperties(prefix="intercept")
public class InterceptorConfig implements WebMvcConfigurer {
    private List<String> excludepath; // 忽略url列表，配置文件注入

    @Resource
    private CoreInterceptor coreInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 不在excludepath列表中的url，交给coreInterceptor处理
        registry.addInterceptor(coreInterceptor).excludePathPatterns(excludepath);
    }
}
